package com.itcast.spring6.ioc.bean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 初始化Spring Bean
 * @author zhangtian105
 * @date 2023/4/27
 * @apiNote
 */
@Slf4j
@Configuration
public class BeanInitialzationTest {
    public static void main(String[] args) {
        // 创建容器
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext() ;
        applicationContext.register(BeanInitialzationTest.class);
        // 启动应用上下文
        applicationContext.refresh();

        // 依赖查找InitialzationBean
        InitialzationBean initialzationBean = applicationContext.getBean(InitialzationBean.class);

        // 关闭spring应用上下文
        applicationContext.close();
    }

    @Bean(initMethod = "initInitialzationBean", destroyMethod = "destoryInitialzationBean")
    public InitialzationBean getInitialzationBean() {
        return new InitialzationBean() ;
    }
}
